<?php
	session_start();
//	echo '<pre>';print_r($_SERVER);echo '</rep>';exit;
	include '../config.php';
	include "../libraries/xl_bo_dem.php";
	$dt_xl_bo_dem = new xl_bo_dem;
	
	//ghi log
	if (!isset($_SESSION['LOG']))
	{
		$_SESSION['LOG'] = 'OK';
		$dt_xl_bo_dem->them($_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT'], date('Y-m-d H:i:s'), $_SERVER['REQUEST_URI']);
	}
	function thong_bao() 
	{
		if ($_SESSION['msg'] != '') 
		{
			?>
			<div class="<?php echo $_SESSION['type_msg']?>"><?php echo $_SESSION['msg']; $_SESSION['msg'] = ''?></div>
            <?php
		}
	}
	if(!isset( $_SESSION['gio_hang']))
	{
		$_SESSION['gio_hang'] = array();
	}
	function ma_hoa($id)
	{
		return base64_encode(base64_encode(base64_encode(base64_encode($id))));
	}
	function giai_ma($id)
	{
		return base64_decode(base64_decode(base64_decode(base64_decode($id))));
	}
	function cat_chuoi($chuoi)
	{
		$str=$chuoi;
		if(strlen($chuoi)<20)
			return $chuoi;
		else 
		{
			$chuoi=trim($chuoi);
			$chuoi = preg_replace("/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/", 'a', $chuoi);
			$chuoi = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/", 'e', $chuoi);
			$chuoi = preg_replace("/(ì|í|ị|ỉ|ĩ)/", 'i', $chuoi);
			$chuoi = preg_replace("/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/", 'o', $chuoi);
			$chuoi = preg_replace("/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/", 'u', $chuoi);
			$chuoi = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/", 'y', $chuoi);
			$chuoi = preg_replace("/(đ)/", 'd', $chuoi);
			$chuoi = preg_replace("/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", 'A', $chuoi);
			$chuoi = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", 'E', $chuoi);
			$chuoi = preg_replace("/(Ì|Í|Ị|Ỉ|Ĩ)/", 'I', $chuoi);
			$chuoi = preg_replace("/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/", 'O', $chuoi);
			$chuoi = preg_replace("/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/", 'U', $chuoi);
			$chuoi = preg_replace("/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", 'Y', $chuoi);
			$chuoi = preg_replace("/(Đ)/", 'D', $chuoi);
			$chuoi=substr($chuoi, 0, 20);
			$chuoi=explode(' ', $chuoi);
			$str=explode(' ', $str);
			if(count($chuoi)==3) 	return $str[0].' '.$str[1].' ...';
			if(count($chuoi)==4)	return $str[0].' '.$str[1].' '.$str[2].' ...';
			if(count($chuoi)==5)	return $str[0].' '.$str[1].' '.$str[2].' '.$str[3].' ...';
			if(count($chuoi)==6)	return $str[0].' '.$str[1].' '.$str[2].' '.$str[3].' '.$str[4].' ...';
			if(count($chuoi)==7)	return $str[0].' '.$str[1].' '.$str[2].' '.$str[3].' '.$str[4].' '.$str[5].' ...';
		}
	}
	
	function convert_vi_to_en($str) 
	{
		$str=trim($str);
		$str = preg_replace("/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/", 'a', $str);
		$str = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/", 'e', $str);
		$str = preg_replace("/(ì|í|ị|ỉ|ĩ)/", 'i', $str);
		$str = preg_replace("/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/", 'o', $str);
		$str = preg_replace("/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/", 'u', $str);
		$str = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/", 'y', $str);
		$str = preg_replace("/(đ)/", 'd', $str);
		$str = preg_replace("/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", 'A', $str);
		$str = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", 'E', $str);
		$str = preg_replace("/(Ì|Í|Ị|Ỉ|Ĩ)/", 'I', $str);
		$str = preg_replace("/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/", 'O', $str);
		$str = preg_replace("/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/", 'U', $str);
		$str = preg_replace("/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", 'Y', $str);
		$str = preg_replace("/(Đ)/", 'D', $str);
		$str = strtolower($str);
		$str = str_replace(" ", "-", $str);
		$str = str_replace("`", "",$str);
		$str = str_replace("~", "",$str);
		$str = str_replace("!", "",$str);
		$str = str_replace("@", "",$str);
		$str = str_replace("#", "",$str);
		$str = str_replace("$", "",$str);
		$str = str_replace("%", "",$str);
		$str = str_replace("^", "",$str);
		$str = str_replace("&", "",$str);
		$str = str_replace("*", "",$str);
		$str = str_replace("(", "",$str);
		$str = str_replace(")", "",$str);
		$str = str_replace("_", "",$str);
		$str = str_replace("+", "",$str);
		$str = str_replace("=", "",$str);
		$str = str_replace("{", "",$str);
		$str = str_replace("[", "",$str);
		$str = str_replace("}", "",$str);
		$str = str_replace("]", "",$str);
		$str = str_replace("|", "",$str);
		$str = str_replace("?", "",$str);
		$str = str_replace(">", "",$str);
		$str = str_replace("<", "",$str);
		$str = str_replace("/", "",$str);
		$str = str_replace("--", "-", str_replace("--","-",$str));
		return $str;
	}
?>